<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
		<link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
		<link rel="stylesheet" type="text/css" href="../../../CSS/common.css">

	</head>

	<body style="padding:0px;background-color: white">
		<div class="easyui-layout " style="width:460px;height:380px;position:relative;margin:0 auto;">
			<div data-options="region:'north'" style="height:80px;">
				<div id="p" class="easyui-panel" title="信息" style="height: 78px;">
					<table cellpadding="2" style="width: 80%;margin-left: 9%;padding-top: 10px;">
						<tr>
							<td width="20%">区域类型</td>
							<td width="80%">
								<input style="width: 87%;" type="REGION_TYPE" id="input_REGION_TYPE" class="easyui-combobox" />
								<a href="#" class="easyui-linkbutton" data-options="iconCls:'icon-add'" onclick="AddRegionTypeName()"></a>
							</td>
						</tr>
						<tr style="display: none;">
							<td></td>
							<td>
								<input style="width: 100%;" type="text" id="input_REGION_TYPE_ID" class="easyui-textbox" />
							</td>
						</tr>
					</table>
				</div>
			</div>
			<div data-options="region:'center',title:'信息'">
				<div id="dl" style="width: 100%;height:200px;"></div>
				<div style="margin-top: 20px;margin-left: 40px;">
					<input class="easyui-textbox" data-options="required:true" id="input_REGION_NAME" style="width:150px;"></input>
					<a href="#" class="easyui-linkbutton" onclick="saveData()" id="add" class="button-group" style="width: 100px;">添加</a>
					<a href="#" class="easyui-linkbutton" onclick="deletedata()" id="delete" class="button-group" style="width: 100px;">删除</a>
				</div>
			</div>
		</div>
		<div id="dlg" class="hiddenDialog">
			<iframe id="ifrmEdit" style="width: 40%;height: 450px;" frameborder="0" scrolling="no"></iframe>
		</div>
	</body>
	<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
	<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="../../../JS/common.js"></script>
	<script type="text/javascript" src="../../../JS/MarketShareFunction/DialogShareFunction.js"></script>
	<script type="text/javascript" src="../../../JS/MarketShareFunction/MarketShareFunction.js"></script>
	<script type="text/javascript">
		$('#input_REGION_TYPE').combobox({
			valueField: 'NAME',
			textField: 'NAME',
			panelHeight: '150',
			method: 'get',
			mode: 'remote',
			url: RemoteLinkAddress + '/market/regiontype/listall.do',
			onSelect: function(record) {
				$("#input_REGION_TYPE_ID").textbox('setValue', record.ID);
				regionList(record.ID);

			}
		});

		function regionList(id) {
			$('#dl').datalist({
				url: RemoteLinkAddress + "/market/region/listall.do?TYPE_ID=" + id,
				method: 'get',
				valueField: 'ID',
				textField: 'NAME',
				lines: true,
				checkbox: true,
			});
		}

		function saveData() { //保存
			var _data = new Object();
			_data.NAME = $("#input_REGION_NAME").textbox("getValue");
			_data.TYPE_ID = $("#input_REGION_TYPE_ID").textbox('getValue');
			submitData(_data);
		}

		function deletedata() { //删除
			var row = $('#dl').datalist('getSelected');
			$.messager.confirm('Confirm', '是否删除', function(r) {
				if(r) {
					$.post(RemoteLinkAddress + "/market/region/delete.do", {
							ID: row.ID
						},
						function(result) {
							if(result.msg == "success") {
								$('#dl').datalist('reload');
								$.messager.alert({ // show success message
									title: '成功',
									msg: '删除成功'
								});
								nextpage();
							} else {
								$.messager.alert({ // show error message
									title: 'Error',
									msg: result.msg
								});
							}
						},
						'json');
				}
			});
		}

		function submitData(_data) {
			var _url = "";
			_url = RemoteLinkAddress + "/market/region/save.do";
			$.ajax({
				dataType: 'JSON',
				url: _url,
				data: _data,
				type: "POST",
				success: function(result) {
					$('#dl').datalist('reload');
					$.messager.alert("提示信息", "保存成功");
				},
				error: function(result) {
					$.messager.alert("错误信息", "保存失败");
				}
			});
		}
		var AddDialog;
		function AddRegionTypeName() {
			var pLocation = "UI/Market/DictData/DictDataAdd.html?id=regiontype";
			$("#ifrmEdit").attr("src", pLocation);
			constructcomboDialog($("#dlg"), "添加基础信息", $("#input_REGION_TYPE"));
			AddDialog.dialog('open');
		}
	</script>

</html>